<template>
	<view class="center">
		<view class="userInfo" @click.capture="toUserInfo">
			<cloud-image width="150rpx" height="150rpx" v-if="hasLogin&&userInfo.avatar_file&&userInfo.avatar_file.url" :src="userInfo.avatar_file.url"></cloud-image>
			
			<view v-else class="defaultAvatarUrl">
				<uni-icons color="#ffffff" size="50" type="camera" />
			</view>
			
			<view class="logo-title">
				<text class="uer-name" v-if="hasLogin">{{userInfo.nickname||userInfo.username||userInfo.mobile}}</text>
				<text class="uer-name" v-else>{{$t('mine.notLogged')}}</text>
				<view  class="user" v-if="!userInfo.newLevel">
					<text>{{userGird}}</text>
				</view>
				<image src="../../static/user-icon/sz.png"  v-if="userInfo.newLevel==1" mode="aspectFit" class="user-icons"></image>
				<image src="../../static/user-icon/ts.png" v-if="userInfo.newLevel==3" mode="aspectFit" class="user-icons"></image>
				<image src="../../static/user-icon/ds.png"  v-if="userInfo.newLevel==2" mode="aspectFit" class="user-icons"></image>
			</view>
		</view>
		<uni-list class="center-list" v-for="(sublist , index) in ucenterList" :key="index">
			<uni-list-item v-for="(item,i) in sublist" :title="item.title" link :rightText="item.rightText" :key="i"
				:clickable="true" :to="item.to" @click="ucenterListClick(item)" :show-extra-icon="true"
				:extraIcon="{type:item.icon,color:'#999'}">
				<template v-slot:footer>
					<view v-if="item.showBadge" class="item-footer">
						<text class="item-footer-text">{{item.rightText}}</text>
						<view class="item-footer-badge"></view>
					</view>
				</template>
			</uni-list-item>
		</uni-list>
	</view>
</template>

<script>
	import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
	import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
	// #ifdef APP
	import UniShare from '@/uni_modules/uni-share/js_sdk/uni-share.js';
	const uniShare = new UniShare()
	// #endif
	const db = uniCloud.database();
	const setTwoPlusOne = uniCloud.importObject('two-plus-one')
	// import {
	// 	store,
	// 	mutations
	// } from '@/uni_modules/uni-id-pages/common/store.js'
	import {
		useUserStore
	} from '@/pinia/user.js'
	import {
		mapState
	} from "pinia"
	
	export default {
		data() {
			return {
				ucenterList: [
					[
						{
							"title": '基本资料',
							"to": '/pages/basic-info/basic-info',
							"icon": "compose"
						},{
							"title": '购买记录',
							"to": '/pages/pay-order/pay-order',
							"icon": "compose"
						},{
							"title": '邀请赚钱',
							"to": '/pages/share/share',
							"icon": "compose"
						},{
							"title": '会员中心',
							"to": '/pages/user/user',
							"icon": "compose"
						},
					],
					[
						{
							"title": '爱情线',
							"to": '/pages/list/love-line',
							"icon": "paperclip"
						},
						{
							"title": '礼物记录',
							"to": '/pages/gift/gift-log',
							"icon": "gift"
						},
						{
							"title": '幸福学院',
							"to": '/pages/asked/asked',
							"icon": "medal-filled"
						},
						{
							"title": '学习中心',
							"to": '/pages/book/list',
							"icon": "medal-filled"
						}
					],
					[
					// 	{
					// 	"title": "信息&客服",
					// 	"to": '/pages/asked/asked',
					// 	"icon": "help"
					// },
					{
						"title": "运营中心",
						"to": '/pages/server-center/operations-center',
						"icon": "help"
					},{
						"title": "服务中心",
						"to": '/pages/server-center/server-center',
						"icon": "help"
					},{
						"title": "建议与反馈",
						"to": '/uni_modules/uni-feedback/pages/opendb-feedback/opendb-feedback',
						"icon": "help"
					}, {
						"title": this.$t('mine.settings'),
						"to": '/pages/ucenter/settings/settings',
						"icon": "gear"
					}],
					// #ifdef APP-PLUS
					[{
						"title": this.$t('mine.about'),
						"to": '/pages/ucenter/about/about',
						"icon": "info"
					}]
					// #endif
				],
				listStyles: {
					"height": "150rpx", // 边框高度
					"width": "150rpx", // 边框宽度
					"border": { // 如果为 Boolean 值，可以控制边框显示与否
						"color": "#eee", // 边框颜色
						"width": "1px", // 边框宽度
						"style": "solid", // 边框样式
						"radius": "100%" // 边框圆角，支持百分比
					}
				},
				// localGird:["普通会员","红娘","月老","联合创始人"],
				localGird:["普通会员","幸福使者","幸福大使","幸福天使","联合创始人"]
			}
		},
		onLoad() {
			
		},
		onShow() {
		},
		computed: {
			...mapState(useUserStore, ['hasLogin', 'userInfo']),
			userGird(){
				let userIndex = this.userInfo.newLevel || 0
				return this.localGird[userIndex]
			},
			// userInfo() {
			// 	return store.userInfo
			// },
			// hasLogin(){
			// 	return store.hasLogin
			// },
		},
		methods: {
			async setIdentity(){
				console.log("setIdentity")
				// let res = await setTwoPlusOne.setIdentity(this.userInfo._id)
				// console.log("res++++++++++++",res)
			},
			toSettings() {
				uni.navigateTo({
					url: "/pages/ucenter/settings/settings"
				})
			},
			signIn() { //普通签到
				this.$refs.signIn.open()
			},
			signInByAd(){ //看激励视频广告签到
				this.$refs.signIn.showRewardedVideoAd()
			},
			/**
			 * 个人中心项目列表点击事件
			 */
			ucenterListClick(item) {
				// console.log("item",item)
				if (!item.to && item.event) {
					this[item.event]();
				}
			},
			async checkVersion() {
				let res = await callCheckVersion()
				console.log(res);
				if (res.result.code > 0) {
					checkUpdate()
				} else {
					uni.showToast({
						title: res.result.message,
						icon: 'none'
					});
				}
			},
			toUserInfo() {
				uni.navigateTo({
					url: '/uni_modules/uni-id-pages/pages/userinfo/userinfo'
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* #ifndef APP-NVUE */
	view {
		display: flex;
		box-sizing: border-box;
		flex-direction: column;
	}

	page {
		background-color: #f8f8f8;
	}
	/* #endif*/
	
	.center {
		flex: 1;
		flex-direction: column;
		background-color: #f8f8f8;
	}

	.userInfo {
		// padding: 20rpx;
		padding-top: 60px;
		// background-image: url(../../static/uni-center/headers.png);
		background-color: #dd356a;
		flex-direction: row;
		padding-left: 20rpx;
		padding-bottom: 20rpx;
		align-items: center;
	}
	.defaultAvatarUrl{
		width: 150rpx;
		height: 150rpx;
		background-color: #eceaea;
		border-radius: 100%;
		justify-content: center;
		align-items: center;
	}
	.logo-title {
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row;
		margin-left: 10px;
	}
	.uer-name {
		height: 100rpx;
		line-height: 100rpx;
		font-size: 28rpx;
		color: #FFFFFF;
	}
	.user{
		margin-right: 10px;
		background-color: #e45400;
		color: #FFFFFF;
		padding: 3px 10px;
		border-radius: 3px;
		font-size: 12px;
	}
	
	.user-icons{
		width: 150rpx;
		height: 150rpx;
		border-radius: 20rpx;
		margin-right: 160rpx;
	}
	
	.center-list {
		margin-bottom: 30rpx;
		background-color: #f9f9f9;
	}

	.center-list-cell {
		width: 750rpx;
		background-color: #007AFF;
		height: 40rpx;
	}

	.grid {
		background-color: #FFFFFF;
		margin-bottom: 6px;
	}

	.uni-grid .text {
		font-size: 16px;
		height: 25px;
		line-height: 25px;
		color: #817f82;
	}

	.uni-grid .item ::v-deep .uni-grid-item__box {
		justify-content: center;
		align-items: center;
	}


	/*修改边线粗细示例*/
	/* #ifndef APP-NVUE */
	.center-list ::v-deep .uni-list--border:after {
		-webkit-transform: scaleY(0.2);
		transform: scaleY(0.2);
		margin-left: 80rpx;
	}

	.center-list ::v-deep .uni-list--border-top,
	.center-list ::v-deep .uni-list--border-bottom {
		display: none;
	}

	/* #endif */
	.item-footer {
		flex-direction: row;
		align-items: center;
	}

	.item-footer-text {
		color: #999;
		font-size: 24rpx;
		padding-right: 10rpx;
	}

	.item-footer-badge {
		width: 20rpx;
		height: 20rpx;
		/* #ifndef APP-NVUE */
		border-radius: 50%;
		/* #endif */
		/* #ifdef APP-NVUE */
		border-radius: 10rpx;
		/* #endif */
		background-color: #DD524D;
	}
</style>